<!DOCTYPE html>
<html lang="zh">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>密码修改</title>
    <link type="text/css" rel="stylesheet" href="{{ url_for('static',filename='layui/css/layui.css') }}" media="all">
    <script type="text/javascript" src="{{ url_for('static',filename='common/js/jquery/jquery.min.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static',filename='layui/layui.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static',filename='common/js/md5.js') }}"></script>
</head>
<body style="overflow:hidden; padding: 20px;">
<form class="layui-form" id="resetPassWord">
    <div class="layui-form-item">
        <label class="layui-form-label">原密码</label>
        <div class="layui-input-block">
            {{ form.old_pass }}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            {{ form.new_pass }}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            {{ form.new_pass_ord }}
        </div>
    </div>
    <div class="layui-form-item">
        <span id="changed_status_show" style="font-size: 11pt;"></span>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            {{ form.csrf_token }}
            {{ form.submit }}
            <button type="button" onclick="close_self()" class="layui-btn layui-btn-primary">取消</button>
        </div>
    </div>
</form>
</body>
<script>
    layui.use('form', function () {
        const form = layui.form;
        //监听提交
        form.on('submit(dataform)', function (data) {
            const old_pass = data.field["old_pass"];
            const new_pass_word = data.field["new_pass"];
            const new_pass_word_ord = data.field["new_pass_ord"];
            if (new_pass_word !== new_pass_word_ord) {
                const msg = "两次输入的密码不一致,请重新输入!";
                layui.layer.alert(msg);
                return false;
            }
            data.field["old_pass"] = hex_md5(old_pass)
            data.field["new_pass"] = hex_md5(new_pass_word)
            $.ajax({
                url: "/system/User/change_password",
                type: "post",
                async: true,
                data: data.field,
                dataType: "json",
                success: function (re, textStatus) {
                    if (re.state === true) {
                        layer.alert("修改成功！", function () {
                            close_self();
                        });
                    } else {
                        layer.alert("修改失败：" + re.msg);
                    }
                }
            });
            return false;
        });
    });

    function close_self() {
        const index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    }
</script>
</html>